log using "C:\Documents and Settings\md177.AD\Desktop\modelresults031407complete_altmodels.log", replace

use "C:\WORK\Research-ArticlesInProgress\Colombia coca cultivation with Cate Russler\data\20070312\newcsts031207.dta", clear

*gen poverty_2=poverty*poverty
*gen displaced_2=displaced*displaced
*gen receipt_2=rec100*rec100

tsset deptid year, yearly
xi: xtreg cocax100 l.cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty i.deptid, fe i(deptid) cl(deptid)  
outreg l.cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty using completeresultsoutreg031407, se coefastr bdec(3) rdec(3) 3aster nolabel ctitle(Model 1, pcse) sigsymb(*,**,***)
outreg l.cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty using completeresultsoutreg031407, beta coefastr bdec(3) rdec(3) 3aster nolabel ctitle(Model 1, beta, pcse) sigsymb(*,**,***) append
*CHOW TEST OF DUMMIES
testparm _Idep*
qui:xi: xtreg cocax100 l.cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty i.deptid, fe i(deptid) cl(deptid)  
*vif

xi: xtreg cocax100 l.cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.poverty_2 i.deptid, fe i(deptid) cl(deptid)  
outreg l.cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.poverty_2 using completeresultsoutreg031407, se coefastr bdec(3) rdec(3) 3aster nolabel ctitle(Model 2, pcse) sigsymb(*,**,***) append
outreg l.cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.poverty_2 using completeresultsoutreg031407, beta coefastr bdec(3) rdec(3) 3aster nolabel ctitle(Model 2 beta, pcse) sigsymb(*,**,***) append
*CHOW TEST OF DUMMIES
testparm _Idep*

xi: xtreg cocax100 l.cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.displaced_2 i.deptid, fe i(deptid) cl(deptid)  
outreg l.cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.displaced_2 using completeresultsoutreg031407, se coefastr bdec(3) rdec(3) 3aster nolabel ctitle(Model 3, pcse) sigsymb(*,**,***) append
outreg l.cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.displaced_2 using completeresultsoutreg031407, beta coefastr bdec(3) rdec(3) 3aster nolabel ctitle(Model 3 beta, pcse) sigsymb(*,**,***) append
*CHOW TEST OF DUMMIES
testparm _Idep*

xi: xtreg cocax100 l.cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.receipt_2 i.deptid, fe i(deptid) cl(deptid)  
outreg l.cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.receipt_2 using completeresultsoutreg031407, se coefastr bdec(3) rdec(3) 3aster nolabel ctitle(Model 4, pcse) sigsymb(*,**,***) append
outreg l.cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.receipt_2 using completeresultsoutreg031407, beta coefastr bdec(3) rdec(3) 3aster nolabel ctitle(Model 4 beta, pcse) sigsymb(*,**,***) append
*CHOW TEST OF DUMMIES
testparm _Idep*

**Prais-winsten regressions
tsset deptid year, yearly
xtgls cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty  , panels(correlated) rhotype(tscorr) nocon
outreg l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty using completeresultsoutreg031407, se coefastr bdec(3) rdec(3) 3aster nolabel ctitle(PW-1, pcse) sigsymb(*,**,***) append
outreg l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty using completeresultsoutreg031407, beta coefastr bdec(3) rdec(3) 3aster nolabel ctitle(PW-1 beta, pcse) sigsymb(*,**,***) append
*CHOW TEST OF DUMMIES
*testparm _Idep*

xtgls cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.poverty_2  , panels(correlated) rhotype(tscorr) nocon
outreg l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.poverty_2 using completeresultsoutreg031407, se coefastr bdec(3) rdec(3) 3aster nolabel ctitle(PW2, pcse) sigsymb(*,**,***) append
outreg l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.poverty_2 using completeresultsoutreg031407, beta coefastr bdec(3) rdec(3) 3aster nolabel ctitle(PW2 beta, pcse) sigsymb(*,**,***) append
*CHOW TEST OF DUMMIES
*testparm _Idep*

xtgls cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.displaced_2  , panels(correlated) rhotype(tscorr) nocon
outreg l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.displaced_2 using completeresultsoutreg031407, se coefastr bdec(3) rdec(3) 3aster nolabel ctitle(PW3 beta, pcse) sigsymb(*,**,***) append
outreg l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.displaced_2 using completeresultsoutreg031407, beta coefastr bdec(3) rdec(3) 3aster nolabel ctitle(PW3 beta, pcse) sigsymb(*,**,***) append
*CHOW TEST OF DUMMIES
*testparm _Idep*

xtgls cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.receipt_2  , panels(correlated) rhotype(tscorr) nocon
outreg l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.receipt_2 using completeresultsoutreg031407, se coefastr bdec(3) rdec(3) 3aster nolabel ctitle(PW4, pcse) sigsymb(*,**,***) append
outreg l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.receipt_2 using completeresultsoutreg031407, beta coefastr bdec(3) rdec(3) 3aster nolabel ctitle(PW4 beta, pcse) sigsymb(*,**,***) append
*CHOW TEST OF DUMMIES
*testparm _Idep*

save "C:\WORK\Research-ArticlesInProgress\Colombia coca cultivation with Cate Russler\data\20070312\newcsts031407.dta", replace

***BEGIN JACKKNIFE CODE*****

tsset deptid year, yearly
xi:jackknife esamp=(160-e(N)) _b _se id=_n(deptid), saving (jackknife1, replace) cl(deptid) :xtreg cocax100 l.cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty i.deptid, fe i(deptid) cl(deptid) noc 

xi:jackknife esamp=(160-e(N)) _b _se id=_n(deptid), saving (jackknife2, replace) cl(deptid) :xtreg cocax100 l.cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.poverty_2 i.deptid, fe i(deptid) cl(deptid) noc 

xi:jackknife esamp=(160-e(N)) _b _se id=_n(deptid), saving (jackknife3, replace) cl(deptid) :xtreg cocax100 l.cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.displaced_2 i.deptid, fe i(deptid) cl(deptid) noc 

xi:jackknife esamp=(160-e(N)) _b _se id=_n(deptid), saving (jackknife4, replace) cl(deptid) :xtreg cocax100 l.cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.receipt_2 i.deptid, fe i(deptid) cl(deptid) noc 

xi:jackknife esamp=(160-e(N)) _b _se id=_n(deptid), saving (jackknife1pw, replace) cl(deptid) :xtreg cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty i.deptid, het correlation(ar1)  noc 

xi:jackknife esamp=(160-e(N)) _b _se id=_n(deptid), saving (jackknife2pw, replace) cl(deptid) :xtreg cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.poverty_2 i.deptid, het correlation(ar1) noc 

xi:jackknife esamp=(160-e(N)) _b _se id=_n(deptid), saving (jackknife3pw, replace) cl(deptid) :xtreg cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.displaced_2 i.deptid, het correlation(ar1) noc 

xi:jackknife esamp=(160-e(N)) _b _se id=_n(deptid), saving (jackknife4pw, replace) cl(deptid) :xtreg cocax100 l.spraykm2 l.g100000 l.corrupt100 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.poverty l.receipt_2 i.deptid, het correlation(ar1) noc 

save "C:\WORK\Research-ArticlesInProgress\Colombia coca cultivation with Cate Russler\data\20070312\newcsts031407.dta", replace

use jackknife1, clear
gen deptid=_n
save jackknife1, replace

use jackknife2, clear
gen deptid=_n
save jackknife2, replace
use jackknife3, clear
gen deptid=_n
save jackknife3, replace
use jackknife4, clear
gen deptid=_n
save jackknife4, replace

use jackknife1pw, clear
gen deptid=_n
save jackknife1pw, replace

use jackknife2pw, clear
gen deptid=_n
save jackknife2pw, replace
use jackknife3pw, clear
gen deptid=_n
save jackknife3pw, replace
use jackknife4pw, clear
gen deptid=_n
save jackknife4pw, replace


**collapsing dataset to means**
use "C:\WORK\Research-ArticlesInProgress\Colombia coca cultivation with Cate Russler\data\20070312\newcsts031407.dta", clear
tsset deptid year, yearly
collapse cocax100 l.cocax100 l.spraykm2 l.g100000 l.pubinfra l.agroecon l.displaced l.rec100 l.roads l.corrupt100 l.poverty, by(deptid)
save datameans031407.dta, replace

***merging sample means into jackknifefiles***

merge deptid using jackknife1, unique sort
gen coca_hat = _jk_1*Lcocax100  + _jk_2*Lspraykm2  + _jk_3*Lg100000  + _jk_4*Lcorrupt100  + _jk_5*Lpubinfra  + _jk_6*Lagroecon  + _jk_7*Ldisplaced  +_jk_8*Lrec100  + _jk_9*Lroads  + _jk_10*Lpoverty 
gen diff_i_hat = cocax100 - coca_hat
save jackknife1w-means, replace

use datameans031407.dta, clear
merge deptid using jackknife2, unique sort
gen coca_hat = _jk_1*Lcocax100  + _jk_2*Lspraykm2  + _jk_3*Lg100000  + _jk_4*Lcorrupt100  + _jk_5*Lpubinfra  + _jk_6*Lagroecon  + _jk_7*Ldisplaced  +_jk_8*Lrec100  + _jk_9*Lroads  + _jk_10*Lpoverty  + _jk_11*Lpoverty*Lpoverty 
gen diff_i_hat = cocax100 - coca_hat
save jackknife2w-means, replace

use datameans031407.dta, clear
merge deptid using jackknife3, unique sort
gen coca_hat = _jk_1*Lcocax100  + _jk_2*Lspraykm2  + _jk_3*Lg100000  + _jk_4*Lcorrupt100  + _jk_5*Lpubinfra  + _jk_6*Lagroecon  + _jk_7*Ldisplaced  +_jk_8*Lrec100  + _jk_9*Lroads  + _jk_10*Lpoverty  + _jk_11*Ldisplaced*Ldisplaced 
gen diff_i_hat = cocax100 - coca_hat
save jackknife3w-means, replace
 
use datameans031407.dta, clear
merge deptid using jackknife4, unique sort
gen coca_hat = _jk_1*Lcocax100  + _jk_2*Lspraykm2  + _jk_3*Lg100000  + _jk_4*Lcorrupt100  + _jk_5*Lpubinfra  + _jk_6*Lagroecon  + _jk_7*Ldisplaced  +_jk_8*Lrec100  + _jk_9*Lroads  + _jk_10*Lpoverty  + _jk_11*Lrec100*Lrec100 
gen diff_i_hat = cocax100 - coca_hat
save jackknife4w-means, replace

use datameans031407.dta, clear
merge deptid using jackknife1pw, unique sort
gen coca_hat = _jk_1*Lspraykm2  + _jk_2*Lg100000  + _jk_3*Lcorrupt100  + _jk_4*Lpubinfra  + _jk_5*Lagroecon  + _jk_6*Ldisplaced  +_jk_7*Lrec100  + _jk_8*Lroads  + _jk_9*Lpoverty 
gen diff_i_hat = cocax100 - coca_hat
save jackknife1pw-w-means, replace

use datameans031407.dta, clear
merge deptid using jackknife2pw, unique sort
gen coca_hat = _jk_1*Lspraykm2  + _jk_2*Lg100000  + _jk_3*Lcorrupt100  + _jk_4*Lpubinfra  + _jk_5*Lagroecon  + _jk_6*Ldisplaced  +_jk_7*Lrec100  + _jk_8*Lroads  + _jk_9*Lpoverty  + _jk_10*Lpoverty*Lpoverty 
gen diff_i_hat = cocax100 - coca_hat
save jackknife2pw-w-means, replace

use datameans031407.dta, clear
merge deptid using jackknife3pw, unique sort
gen coca_hat = _jk_1*Lspraykm2  + _jk_2*Lg100000  + _jk_3*Lcorrupt100  + _jk_4*Lpubinfra  + _jk_5*Lagroecon  + _jk_6*Ldisplaced  +_jk_7*Lrec100  + _jk_8*Lroads  + _jk_9*Lpoverty  + _jk_10*Ldisplaced*Ldisplaced 
gen diff_i_hat = cocax100 - coca_hat
save jackknife3pw-w-means, replace

use datameans031407.dta, clear
merge deptid using jackknife4pw, unique sort
gen coca_hat = _jk_1*Lspraykm2  + _jk_2*Lg100000  + _jk_3*Lcorrupt100  + _jk_4*Lpubinfra  + _jk_5*Lagroecon  + _jk_6*Ldisplaced  +_jk_7*Lrec100  + _jk_8*Lroads  + _jk_9*Lpoverty  + _jk_10*Lrec100*Lrec*100 
gen diff_i_hat = cocax100 - coca_hat
save jackknife4pw-w-means, replace

clear
log cl


